//package com.eastfair.es.netty;
//
//import cn.hutool.core.collection.CollectionUtil;
//import com.eastfair.es.entity.AllLog;
//import com.eastfair.es.util.EsDeatilUtil;
//import com.eastfair.es.vo.AllLogSimpleVO;
//import com.eastfair.es.vo.AllLogVO;
//import com.eastfair.netty.common.LocalSession;
//import com.eastfair.netty.common.SessionManger;
//import com.eastfair.netty.model.StringMsg;
//import com.eastfair.netty.server.NettyServerBootstrap;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.BeanUtils;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.UUID;
//import java.util.stream.Collectors;
//
//public class NettyHander {
//    public static void startNetty() {
//        try {
//            NettyServerBootstrap bootstrap = new NettyServerBootstrap(9999);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//    }
//
//    public static void sendMsg(List<AllLog> allLogList) {
//        List<LocalSession> localSessionList = SessionManger.queryAllSession();
//        if (CollectionUtil.isEmpty(allLogList) || CollectionUtil.isEmpty(localSessionList)) {
//            return;
//        }
//        StringMsg stringMsgOfNoAppName = assmbleMsg(filterSimple(allLogList, null));
//        for (LocalSession localSession : localSessionList) {
//            if (localSession.getUser() != null && StringUtils.isNotBlank(localSession.getUser().getAppName())) {
//                StringMsg stringMsg = assmbleMsg(filterSimple(allLogList, localSession.getUser().getAppName()));
//                if (stringMsg != null) {
//                    localSession.getChannel().writeAndFlush(stringMsg);
//                }
//            } else if (localSession.getUser() != null && StringUtils.isBlank(localSession.getUser().getAppName())) {
//                if (stringMsgOfNoAppName != null) {
//                    localSession.getChannel().writeAndFlush(stringMsgOfNoAppName);
//                }
//            }
//        }
//    }
//
//    public static StringMsg assmbleMsg(List<AllLogSimpleVO> allLogSimpleVOList) {
//        if (CollectionUtil.isNotEmpty(allLogSimpleVOList)) {
//            StringMsg message = new StringMsg();
//            message.setType(5);
//            message.setData(allLogSimpleVOList.stream().map(AllLogSimpleVO::getMsg).collect(Collectors.toList()));
//            return message;
//        }
//        return null;
//    }
//
//
//    public static List<AllLogSimpleVO> filterSimple(List<AllLog> allLogList, String appName) {
//        List<AllLog> allLogListOfAppname = null;
//        if (StringUtils.isNotBlank(appName)) {
//            allLogListOfAppname = allLogList.stream().filter(s -> appName.equals(s.getAppName())).collect(Collectors.toList());
//        } else {
//            allLogListOfAppname = allLogList;
//        }
//        List<AllLogVO> allLogVOList = new ArrayList<>();
//        if (CollectionUtil.isNotEmpty(allLogListOfAppname)) {
//            for (AllLog allLog : allLogListOfAppname) {
//                AllLogVO allLogVO = new AllLogVO();
//                BeanUtils.copyProperties(allLog, allLogVO);
//                allLogVOList.add(allLogVO);
//            }
//        }
//        List<AllLogSimpleVO> allLogSimpleVOList = EsDeatilUtil.assmbleDetailSimpleStrOfList(allLogVOList);
//        return allLogSimpleVOList;
//    }
//}
